<?php
include("include/conn.php");
require('include/Smarty/libs/Smarty.class.php');

$fine = 0;
$amount = 0;
$selectBhatthiBook    = "SELECT bhatthibookdetail.fine, bhatthibookdetail.amount,bhatthibookdetail.CrDr,bhatthibookdetail.bhatthiBookId,
                                bhatthibook.bhatthiDate,bhatthibook.bhatthiPartyId,bhatthibook.bhatthiBookId 
                           FROM bhatthibookdetail
                           JOIN bhatthibook
                          WHERE bhatthibook.bhatthiPartyId = ".$_POST['partyId']."
                            AND bhatthibookdetail.bhatthiBookId = bhatthibook.bhatthiBookId 
                            AND bhatthibook.bhatthiDate <= '".date("Y-m-d")."'
                       ORDER BY bhatthibook.bhatthiDate";
$selectBhatthiBookRes = mysql_query($selectBhatthiBook);
while($row = mysql_fetch_assoc($selectBhatthiBookRes))
{
	if($row['CrDr'] == "Dr")
	{
     $fine   += $row['fine'];
     $amount += $row['amount'];
	}
	else
	{
    $fine    -= $row['fine'];
    $amount  -= $row['amount'];
	}
}


echo number_format($fine, 0, '.', '').",".number_format($amount, 0, '.', '');
//echo "<b>Prev. Fine</b> <input type='text' name='partyFine' id='partyFine' value='".number_format($fine, 2, '.', '')."'/> ";
//echo "<b>Prev. Amount</b> <input type='text' name='partyAmount' id='partyAmount' value='".number_format($amount, 2, '.', '')."'/>";
?>